package com.yinhe.music.yhmusic.personal;

import com.yinhe.music.yhmusic.base.BasePresenter;
import com.yinhe.music.yhmusic.base.IBaseModel;
import com.yinhe.music.yhmusic.network.response.ResponseTransformer;

public class UserInfoPresenter extends BasePresenter<IBaseModel, UserInfoContract.IUserInfoView> implements UserInfoContract.IUserInfoPresenter {

    @Override
    public void getUserInfo(String userId) {
        if (getView() == null) {
            return;
        }

        getView().showLoading();

        addSubscription(mModel.getOtherUserInfo(userId)
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(userInfo -> {
                            getView().hideLoading();
                            getView().setUserInfoUI(userInfo);
                        },
                        throwable -> {
                            getView().hideLoading();
                            getView().showMessage(throwable);
                        }));
    }
}
